<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="API docs for the handleEvent method from the VirtualJoystick class, for the Dart programming language.">
  <title>handleEvent method - VirtualJoystick class - spritewidget library - Dart API</title>
  <!-- required because all the links are pseudo-absolute -->
  <base href="../..">

  <link href="https://fonts.googleapis.com/css?family=Source+Code+Pro:500,400i,400,300|Source+Sans+Pro:400,300,700" rel="stylesheet">
  <link rel="stylesheet" href="static-assets/github.css">
  <link rel="stylesheet" href="static-assets/styles.css">
  <link rel="icon" href="static-assets/favicon.png">

</head>

<body>

<div id="overlay-under-drawer"></div>

<header id="title">
  <button id="sidenav-left-toggle" type="button">&nbsp;</button>
  <ol class="breadcrumbs gt-separated dark hidden-xs">
    <li><a href="index.html">spritewidget</a></li>
    <li><a href="spritewidget/spritewidget-library.html">spritewidget</a></li>
    <li><a href="spritewidget/VirtualJoystick-class.html">VirtualJoystick</a></li>
    <li class="self-crumb">handleEvent method</li>
  </ol>
  <div class="self-name">handleEvent</div>
  <form class="search navbar-right" role="search">
    <input type="text" id="search-box" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
  </form>
</header>

<main>

  <div class="col-xs-6 col-sm-3 col-md-2 sidebar sidebar-offcanvas-left">
    <h5>VirtualJoystick class</h5>
    <ol>
      <li class="section-title"><a href="spritewidget/VirtualJoystick-class.html#constructors">Constructors</a></li>
      <li><a href="spritewidget/VirtualJoystick/VirtualJoystick.html">VirtualJoystick</a></li>
    
      <li class="section-title">
        <a href="spritewidget/VirtualJoystick-class.html#instance-properties">Properties</a>
      </li>
      <li><a href="spritewidget/VirtualJoystick/isDown.html">isDown</a></li>
      <li><a href="spritewidget/VirtualJoystick/value.html">value</a></li>
      <li class="inherited"><a href="spritewidget/Node/actions.html">actions</a></li>
      <li class="inherited"><a href="spritewidget/Node/children.html">children</a></li>
      <li class="inherited"><a href="spritewidget/Node/constraints.html">constraints</a></li>
      <li class="inherited"><a href="spritewidget/Node/handleMultiplePointers.html">handleMultiplePointers</a></li>
      <li class="inherited"><a href="dart-core/Object/hashCode.html">hashCode</a></li>
      <li class="inherited"><a href="spritewidget/Node/inverseTransformMatrix.html">inverseTransformMatrix</a></li>
      <li class="inherited"><a href="spritewidget/Node/parent.html">parent</a></li>
      <li class="inherited"><a href="spritewidget/Node/paused.html">paused</a></li>
      <li class="inherited"><a href="spritewidget/NodeWithSize/pivot.html">pivot</a></li>
      <li class="inherited"><a href="spritewidget/Node/position.html">position</a></li>
      <li class="inherited"><a href="spritewidget/Node/rotation.html">rotation</a></li>
      <li class="inherited"><a href="dart-core/Object/runtimeType.html">runtimeType</a></li>
      <li class="inherited"><a href="spritewidget/Node/scale.html">scale</a></li>
      <li class="inherited"><a href="spritewidget/Node/scaleX.html">scaleX</a></li>
      <li class="inherited"><a href="spritewidget/Node/scaleY.html">scaleY</a></li>
      <li class="inherited"><a href="spritewidget/NodeWithSize/size.html">size</a></li>
      <li class="inherited"><a href="spritewidget/Node/skewX.html">skewX</a></li>
      <li class="inherited"><a href="spritewidget/Node/skewY.html">skewY</a></li>
      <li class="inherited"><a href="spritewidget/Node/spriteBox.html">spriteBox</a></li>
      <li class="inherited"><a href="spritewidget/Node/transformMatrix.html">transformMatrix</a></li>
      <li class="inherited"><a href="spritewidget/Node/userInteractionEnabled.html">userInteractionEnabled</a></li>
      <li class="inherited"><a href="spritewidget/Node/visible.html">visible</a></li>
      <li class="inherited"><a href="spritewidget/Node/zPosition.html">zPosition</a></li>
    
      <li class="section-title"><a href="spritewidget/VirtualJoystick-class.html#instance-methods">Methods</a></li>
      <li><a href="spritewidget/VirtualJoystick/handleEvent.html">handleEvent</a></li>
      <li><a href="spritewidget/VirtualJoystick/paint.html">paint</a></li>
      <li class="inherited"><a href="spritewidget/Node/addChild.html">addChild</a></li>
      <li class="inherited"><a href="spritewidget/Node/applyConstraints.html">applyConstraints</a></li>
      <li class="inherited"><a href="spritewidget/NodeWithSize/applyTransformForPivot.html">applyTransformForPivot</a></li>
      <li class="inherited"><a href="spritewidget/Node/computeTransformMatrix.html">computeTransformMatrix</a></li>
      <li class="inherited"><a href="spritewidget/Node/convertPointFromNode.html">convertPointFromNode</a></li>
      <li class="inherited"><a href="spritewidget/Node/convertPointToBoxSpace.html">convertPointToBoxSpace</a></li>
      <li class="inherited"><a href="spritewidget/Node/convertPointToNodeSpace.html">convertPointToNodeSpace</a></li>
      <li class="inherited"><a href="spritewidget/Node/invalidateTransformMatrix.html">invalidateTransformMatrix</a></li>
      <li class="inherited"><a href="spritewidget/NodeWithSize/isPointInside.html">isPointInside</a></li>
      <li class="inherited"><a href="dart-core/Object/noSuchMethod.html">noSuchMethod</a></li>
      <li class="inherited"><a href="spritewidget/Node/removeAllChildren.html">removeAllChildren</a></li>
      <li class="inherited"><a href="spritewidget/Node/removeChild.html">removeChild</a></li>
      <li class="inherited"><a href="spritewidget/Node/removeFromParent.html">removeFromParent</a></li>
      <li class="inherited"><a href="spritewidget/Node/spriteBoxPerformedLayout.html">spriteBoxPerformedLayout</a></li>
      <li class="inherited"><a href="dart-core/Object/toString.html">toString</a></li>
      <li class="inherited"><a href="spritewidget/Node/update.html">update</a></li>
    
      <li class="section-title inherited"><a href="spritewidget/VirtualJoystick-class.html#operators">Operators</a></li>
      <li class="inherited"><a href="dart-core/Object/operator_equals.html">operator ==</a></li>
    
    
    
    </ol>
  </div><!--/.sidebar-offcanvas-->

  <div class="col-xs-12 col-sm-9 col-md-8 main-content">
    <h1>handleEvent method</h1>

    <section class="multi-line-signature">
      <div>
        <ol class="annotation-list">
          <li>@override</li>
        </ol>
      </div>
      <span class="returntype"><a href="dart-core/bool-class.html">bool</a></span>
      <span class="name ">handleEvent</span>
(<wbr><span class="parameter" id="handleEvent-param-event"><span class="type-annotation"><a href="spritewidget/SpriteBoxEvent-class.html">SpriteBoxEvent</a></span> <span class="parameter-name">event</span></span>)
    </section>
    <section class="desc markdown">
      <p>Handles an event, such as a pointer (touch or mouse) event.</p>
<p>Override this method to handle events. The node will only receive events if the <a href="spritewidget/Node/userInteractionEnabled.html">userInteractionEnabled</a> property
is set to true and the <a href="spritewidget/NodeWithSize/isPointInside.html">isPointInside</a> method returns true for the position of the pointer down event (default
behavior provided by <a href="spritewidget/NodeWithSize-class.html">NodeWithSize</a>). Unless <a href="spritewidget/Node/handleMultiplePointers.html">handleMultiplePointers</a> is set to true, the node will only receive
events for the first pointer that is down.</p>
<p>Return true if the node has consumed the event, if an event is consumed it will not be passed on to nodes behind
the current node.</p>
<pre class="language-dart"><code>// MyTouchySprite gets transparent when we touch it
class MyTouchySprite extends Sprite {

  MyTouchySprite(Image img) : super (img) {
    userInteractionEnabled = true;
  }

  bool handleEvent(SpriteBoxEvent event) {
    if (event.type == PointerDownEvent) {
      opacity = 0.5;
    }
    else if (event.type == PointerUpEvent) {
      opacity = 1.0;
    }
    return true;
  }
}
</code></pre>
    </section>
    
    <section class="summary source-code" id="source">
      <h2><span>Implementation</span> </h2>
      <pre class="language-dart"><code class="language-dart">@override
bool handleEvent(SpriteBoxEvent event) {
  if (event.type == PointerDownEvent) {
    _pointerDownAt = event.boxPosition;
    actions.stopAll();
    _isDown = true;
  }
  else if (event.type == PointerUpEvent || event.type == PointerCancelEvent) {
    _pointerDownAt = null;
    _value = Offset.zero;
    ActionTween moveToCenter = new ActionTween((a) { _handlePos = a; }, _handlePos, _center, 0.4, Curves.elasticOut);
    actions.run(moveToCenter);
    _isDown = false;
  } else if (event.type == PointerMoveEvent) {
    Offset movedDist = event.boxPosition - _pointerDownAt;

    _value = new Offset(
      (movedDist.dx &#47; 80.0).clamp(-1.0, 1.0),
      (movedDist.dy &#47; 80.0).clamp(-1.0, 1.0));

      _handlePos = _center + new Offset(_value.dx * 40.0, _value.dy * 40.0);
  }
  return true;
}</code></pre>
    </section>

  </div> <!-- /.main-content -->

  <div class="col-xs-6 col-sm-6 col-md-2 sidebar sidebar-offcanvas-right">
  </div><!--/.sidebar-offcanvas-->

</main>

<footer>
  <span class="no-break">
    spritewidget 0.9.16
  </span>

</footer>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="static-assets/typeahead.bundle.min.js"></script>
<script src="static-assets/highlight.pack.js"></script>
<script src="static-assets/URI.js"></script>
<script src="static-assets/script.js"></script>


</body>

</html>
